package logic

import (
	"context"
	"fmt"
	"shell/houserpc/houserpc"
	"shell/houserpc/internal/svc"
	"shell/models/mysql"
	"strings"

	"github.com/zeromicro/go-zero/core/logx"
)

type SeekAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSeekAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SeekAddLogic {
	return &SeekAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SeekAddLogic) SeekAdd(in *houserpc.SeekAddRequest) (*houserpc.SeekAddResponse, error) {
	// todo: add your logic here and delete this line
	var seek mysql.Seek

	mysql.DB.Debug().Find(&seek)

	if strings.Contains("中介费", in.Context) || strings.Contains("虚假", in.Context) {
		return nil, fmt.Errorf("你所提问的问题里含有敏感词,请你修改后,重新提交问题")
	}

	seek = mysql.Seek{
		UserId:  in.UserId,
		HouseId: in.HouseId,
		Context: in.Context,
	}
	mysql.DB.Debug().Create(&seek)
	return &houserpc.SeekAddResponse{
		SeekId: int64(seek.ID),
	}, nil
}
